package com.open.capacity.study.controller;

import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.exception.service.ServiceException;
import com.open.capacity.common.model.LearnProcess;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.log.annotation.LogAnnotation;
import com.open.capacity.study.service.LearnProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/learnRate")
@Api(tags = "LEARN-RATE API")
public class LearnProcessController {

    @Autowired
    private LearnProcessService learnProcessService;
    /**
     * 添加用户学习进度
     */
    @PostMapping("/insert")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @ApiOperation(value = "添加用户学习进度")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result insert(@RequestBody LearnProcess learnProcess) throws ControllerException{
        try {
            return learnProcessService.insert(learnProcess);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }

    /**
     * 修改学习总结和评分
     */
    @PostMapping("/update")
    //权限注解（暂无）
    @PreAuthorize("hasAnyAuthority('learn:update/grade')")
    @ApiOperation(value = "修改评价和评分")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result updateScore(@RequestBody LearnProcess learnProcess) throws ControllerException{
        try {
            return learnProcessService.updateScore(learnProcess);
        } catch (ServiceException e) {
            throw new ControllerException(e);
        }
    }
    /**
     * 修改学习总结和评分
     */
    @PostMapping("/updateSummary")
    //权限注解（暂无）
    @ApiOperation(value = "修改评价和评分")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result updateSummary(@RequestBody LearnProcess learnProcess) throws ControllerException{
        try {
            return learnProcessService.updateSummary(learnProcess);
        } catch (ServiceException e) {
            throw new ControllerException(e);
        }
    }
    /**
     * 查询
     */
    @GetMapping("/query")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @ApiOperation(value = "查询学习进度阶段信息")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public PageResult<LearnProcess> findList (@RequestParam Map<String,Object> params) throws ControllerException{
        try {
            return learnProcessService.findList(params);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }

    /**
     * 其他查询
     */
    @GetMapping("/otherQuery")
    //权限注解（暂无）
    //@PreAuthorize("hasAnyAuthority('')")
    @ApiOperation(value = "其他查询")
    @LogAnnotation(module = "study-center", recordRequestParam = false)
    public Result otherQuery (@RequestParam Map<String,Object> params) throws ControllerException{
        try {
            return learnProcessService.otherQuery(params);
        }catch (ServiceException e){
            throw new ControllerException(e);
        }
    }
}
